package com.black.platform.dictionary.service.handler.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.black.common.web.PageQuery;
import com.black.platform.dictionary.po.DictionaryCategory;
import com.black.platform.dictionary.service.bz.DictionaryCategoryService;
import com.black.platform.dictionary.service.handler.DictionaryCategoryHandlerService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DictionaryCategoryHandlerServiceImpl implements DictionaryCategoryHandlerService {

    private final DictionaryCategoryService dictionaryCategoryService;

    @Override
    public IPage<DictionaryCategory> search(PageQuery<DictionaryCategory> searchVo) {
        QueryWrapper<DictionaryCategory> query = new QueryWrapper<>();
        DictionaryCategory queryData = searchVo.getQueryData();
        if (!StringUtils.isEmpty(queryData.getName())) {
            query.like("name", queryData.getName());
        }
        return dictionaryCategoryService.page(searchVo.getPager(), query);
    }

    @Override
    public List<DictionaryCategory> getAllCategory() {
        return dictionaryCategoryService.list();
    }

    @Override
    public boolean save(DictionaryCategory dictionaryCategory) {
        return dictionaryCategoryService.save(dictionaryCategory);
    }

    @Override
    public boolean update(DictionaryCategory dictionaryCategory) {
        return dictionaryCategoryService.updateById(dictionaryCategory);
    }

    @Override
    public DictionaryCategory getById(Long id) {
        return dictionaryCategoryService.getById(id);
    }

    @Override
    public boolean deleteByIds(List<Long> ids) {
        return dictionaryCategoryService.removeByIds(ids);
    }


}
